<?php include('actions/admin_auth.php') ?>
<?php include('includes/start.php'); ?>

<h2>Manage Media Types</h2>

<?php   if(isset($_GET['err']) && $_GET['err'] )
			echo "<font id='std_padding'  color='red'>Error: " . $_GET['err'] . "</font>"; 
		else if(isset($_GET['msg'])  && $_GET['msg'])
			echo "<font id='std_padding'  color='#0246FF'>" . $_GET['msg'] . "</font>";
?>

<?php 

if(!session_id()) session_start(); 
$con = mysql_connect($dbserver, $dbuser, $dbpass);
if ($con)
{
	mysql_select_db($db, $con);
	

		$q = $all_media_types;
		$result = mysql_query($q);
		mysql_close($con);
		
}
else{
	echo "<font color='red'> Error Connecting to DB!</font>";
}

?>

<table id='DB_search_results'>
	<tr>
		<th>Name</th>
		<th>Description</th>
		<th>Checkout Duration (Days)</th>
		<th>Renewal Limit (Times)</th>
		<th>Late Fee ($)</th>
		<th>Accumulation Time (Days)</th>
		
	</tr>
	<tr>
		<form action='actions/add_media_type.php' method='POST' >
			<td><input size='16' type='text' name='name' /></td>
			<td><input size='16' type='text' name='description'/></td>
			<td><input size='16' type='text' name='checkout_duration'/></td>
			<td><input size='16' type='text' name='renewal_limit'/></td>
			<td><input size='16' type='text' name='late_fee'/></td>
			<td><input size='16' type='text' name='fee_accumulation_time'/></td>
			<td>&nbsp;&nbsp;&nbsp;<input type="submit" value="Add New" /></td>
		</form>
	</tr>
<?php
	while($media_type = mysql_fetch_array($result)){
		if(!isset($_POST['media_edit']) || $_POST['media_edit'] != $media_type['media_type_id']){
			echo "<tr>";
			echo "<td>".$media_type['name']."</td>";
			echo "<td>".$media_type['description']."</td>";
			echo "<td>".$media_type['checkout_duration']." days</td>";
			echo "<td>".$media_type['renewal_limit']." times</td>";
			echo "<td>$". number_format(((double)$media_type['late_fee'])/((double)100), 2) ."</td>";
			echo "<td>".$media_type['fee_accumulation_time']." days</td>";
			echo "<td><form action='/manage_media_types.php' method='post'> <input type='hidden' name='media_edit' value='".$media_type['media_type_id']."' />&nbsp;&nbsp;&nbsp;<input type='submit' value='Edit' /></form></td>";
			echo "</tr>";
		}
		else{
			echo "<tr>";
			echo "<form action='actions/edit_media_type.php' method='POST' >";
			echo "<td> <input size='16' type='text' name='name' value='".$media_type['name']."'/></td>";
			echo "<td> <input size='16' type='text' name='description' value='".$media_type['description']."'/></td>";
			echo "<td> <input size='16' type='text' name='checkout_duration' value='".$media_type['checkout_duration']."'/></td>";
			echo "<td> <input size='16' type='text' name='renewal_limit' value='".$media_type['renewal_limit']."'/></td>";
			echo "<td> <input size='16' type='text' name='late_fee' value='".number_format(((double)$media_type['late_fee'])/((double)100), 2)."'/></td>";
			echo "<td> <input size='16' type='text' name='fee_accumulation_time' value='".$media_type['fee_accumulation_time']."'/></td>";
			echo "<td> <input type='hidden' name='media_type_id' value='".$media_type['media_type_id']."' />";
			echo "&nbsp;&nbsp;&nbsp;<input type='submit' value='Save' /></form></td>";
			echo "</form></tr>";
		}
	}
?>
</table>

<?php include('includes/stop.php'); ?>
